<?php
namespace app\admin\controller;
use think\Db;
class Casein extends Base{
    public function casein_list(){
        $keyword=input('get.keyword');
        $state=input('get.state');
        if (!empty(input('get.fromtime'))) {
            $fromtime=strtotime(input('get.fromtime'));
        }else{
            $fromtime=0;
        }
        if (!empty(input('get.totime'))) {
            $totime=strtotime(input('get.totime'))+86400;
        }else{
            $totime=time();
        }
        $map = [
            ['time', '>', $fromtime],
            ['time', '<', $totime]
        ];
        if($state==0){
            array_push($map,['state','<',4]);
        }else{
            array_push($map,['state','=',$state]);
        }
        $list=Db::name('caseings')->where($map)->where('name|phone|company','like',"%{$keyword}%")->order('id desc')->paginate(10);
        $count=Db::name('caseings')->where($map)->where('name|phone|company','like',"%{$keyword}%")->count();
        $data=$list->all();
        $this->assign('keyword',input('get.keyword'));
        $this->assign('fromtime',input('get.fromtime'));
        $this->assign('totime',input('get.totime'));
        $this->assign('state',$state);
        $this->assign('data',$data);
        $this->assign('list',$list);
        $this->assign('count',$count);
        return $this->fetch();
    }
    public function state_ing(){
        $id=input('param.id');
        $status = Db::name('caseings')->where(array('id'=>$id))->update(['state'=>2]);
        if($status){
            return json(['code' => 200,'msg' => '进入处理中']);
        }else{
            return json(['code' => 500,'msg' => '出错']);
        }
    }
    public function state_ed(){
        $id=input('param.id');
        $status = Db::name('caseings')->where(array('id'=>$id))->update(['state'=>3]);
        if($status){
            return json(['code' => 200,'msg' => '已处理']);
        }else{
            return json(['code' => 500,'msg' => '出错']);
        }
    }
}
